处理文件创建失败的错误类型

chengzhenyu 7 years ago
parent
commit
ad4b2ea739

+ 14 - 1
app/src/main/java/ai/pai/lensman/dslr/CameraService.java

@@ -30,6 +30,7 @@ public class CameraService extends Service {
30 30
     public static final int MSG_CAMERA_INIT_SUCCESS = 8000;
31 31
     public static final int MSG_CAMERA_CONN_ERROR = 8001;
32 32
     public static final int MSG_CAMERA_NEW_PHOTO_FOUND = 8002;
33
+    public static final int MSG_SDCARD_ERROR = 8003;
33 34
 
34 35
 
35 36
     public static final String EXTRA_CMD = "cmd";
@@ -41,6 +42,7 @@ public class CameraService extends Service {
41 42
     private static final String MSG_TYPE_CAMERA_ERROR = "camero error";//相机错误,可能是线松动了。先exit,然后重新init
42 43
     private static final String MSG_TYPE_NOT_INIT = "not init";  //需要初始化
43 44
     private static final String MSG_TYPE_TIME_OUT = "time out";  //继续调用waitforevent
45
+    private static final String MSG_TYPE_CREATE_FILE_ERROR = "creat error";//照片文件创建失败
44 46
 
45 47
     private static final int MAX_NO_PHOTO_COUNT = 500;
46 48
     private int count = 0;
@@ -176,7 +178,18 @@ public class CameraService extends Service {
176 178
                 sendCameraIntent(bundle);
177 179
                 stopCameraService();
178 180
             }else if(MSG_TYPE_TIME_OUT.equalsIgnoreCase(eventMsg)){
179
-
181
+                count++;
182
+                if(count>=MAX_NO_PHOTO_COUNT){
183
+                    LogHelper.d("czy","CameraService fetchPhotoTask 太久没发现新照片了,重新连接试试");
184
+                    Bundle bundle = new Bundle();
185
+                    bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
186
+                    sendCameraIntent(bundle);
187
+                    stopCameraService();
188
+                }
189
+            }else if(MSG_TYPE_CREATE_FILE_ERROR.equalsIgnoreCase(eventMsg)){
190
+                Bundle bundle = new Bundle();
191
+                bundle.putInt(EXTRA_STATUS_PART, MSG_SDCARD_ERROR);
192
+                sendCameraIntent(bundle);
180 193
             }else{
181 194
                 String sub = eventMsg.substring(0,1);
182 195
                 if(TextUtils.isDigitsOnly(sub)){

+ 5 - 0
app/src/main/java/ai/pai/lensman/session/SessionInteractor.java

@@ -29,6 +29,7 @@ import static ai.pai.lensman.dslr.CameraService.EXTRA_STATUS_PART;
29 29
 import static ai.pai.lensman.dslr.CameraService.MSG_CAMERA_CONN_ERROR;
30 30
 import static ai.pai.lensman.dslr.CameraService.MSG_CAMERA_INIT_SUCCESS;
31 31
 import static ai.pai.lensman.dslr.CameraService.MSG_CAMERA_NEW_PHOTO_FOUND;
32
+import static ai.pai.lensman.dslr.CameraService.MSG_SDCARD_ERROR;
32 33
 
33 34
 public class SessionInteractor implements Callback{
34 35
 
@@ -62,6 +63,7 @@ public class SessionInteractor implements Callback{
62 63
         void onSessionPhotoCaptured(PhotoBean bean);
63 64
         void onSessionEnd(String session);
64 65
         void onCameraStatusChanged(String status);
66
+        void onSDCardError();
65 67
     }
66 68
 
67 69
     public void startSession(){
@@ -123,6 +125,9 @@ public class SessionInteractor implements Callback{
123 125
                 listener.onCameraStatusChanged("camera connection error");
124 126
                 listener.onSessionStartError(sessionBean.sessionId);
125 127
                 mHandler.sendEmptyMessageDelayed(MSG_RETRY_INIT_CAMERA,3000);
128
+            }else if(status == MSG_SDCARD_ERROR){
129
+                listener.onCameraStatusChanged("sdcard error");
130
+                listener.onSDCardError();
126 131
             }else if(status == MSG_CAMERA_NEW_PHOTO_FOUND){
127 132
                 String eventMsg = intent.getStringExtra(EXTRA_DATA_PART);
128 133
                 LogHelper.d(TAG,"fetchPhotoTask new photo found");

+ 5 - 0
app/src/main/java/ai/pai/lensman/session/SessionPresenter.java

@@ -108,6 +108,11 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
108 108
     }
109 109
 
110 110
     @Override
111
+    public void onSDCardError() {
112
+        sessionView.showToast(App.getAppContext().getString(R.string.sdcard_error));
113
+    }
114
+
115
+    @Override
111 116
     public void swipeToDeletePhoto(int index) {
112 117
         if(index<0 || index>= photoList.size()){
113 118
             return;

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -141,4 +141,6 @@
141 141
     <string name="session_photo_limit">只显示最近200张照片,您可以到存储卡目录查看更多</string>
142 142
 
143 143
     <string name="usb_permission_denied">请检查设备是否已开放root权限</string>
144
+
145
+    <string name="sdcard_error">保存照片失败,请检查手机存储卡</string>
144 146
 </resources>